package v2.parser.tree

import v2.parser.{Link, Type, Slotted, Value}

/**
 * @author bweber
 * @version $Rev$, $Date$
 */

class TypedTree (val parentNode: TypedTree, val name: String, val currentNode: Value) {
  def listChildren(): List[String] = {
    var attrs = List[String]()
    if (currentNode.isInstanceOf[Slotted]) {
      currentNode.asInstanceOf[Slotted].slots.foreach {
        slot =>
                attrs = slot.attrref :: attrs
      }
    }
    else if (currentNode.isInstanceOf[Type]) {
      currentNode.asInstanceOf[Type].attrdefs.foreach {
        attr =>
                attrs = attr.name :: attrs
      }
    }
    else if ( currentNode.isInstanceOf[Link] ) {
      attrs = "link to: " + currentNode.asInstanceOf[Link].pointsAt :: attrs
    }
    attrs
  }

  def getChild(name: String): Value = {
    if (currentNode.isInstanceOf[Slotted]) {
      return currentNode.asInstanceOf[Slotted].getAttr(name)
    }
    else if (currentNode.isInstanceOf[Type]) {
      return currentNode.asInstanceOf[Type].getAttribute(name)
    }
    throw new RuntimeException("No such child: " + name)
  }

}

object TypedTree {
  def apply(name: String, startingPoint: Value) = {

    new TypedTree(null, name, startingPoint)

  }

}